package com.cuijun.spring5.aopAnnotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//增强类,并在上面增加注解@Aspect，生成代理对象
@Component
@Aspect
@Order(3)
public class UserProxy {

    //相同切入点抽取
    @Pointcut(value = "execution(* com.cuijun.spring5.aopAnnotation.User.add(..))")
    public void pointDemo(){
    }

    //前置通知，在指向方法之前执行
    @Before(value = "pointDemo()")
    public void before(){
        System.out.println("before.....");
    }

    //后置通知，在指向方法之后执行
    @After(value = "pointDemo()")
    public void after(){
        System.out.println("after.....");
    }

    //返回通知，在方法返回结果之后执行
    @AfterReturning(value = "pointDemo()")
    public void afterReturning(){
        System.out.println("afterReturning.....");
    }

    //异常通知
    @AfterThrowing(value = "pointDemo()")
    public void afterThrowing(){
        System.out.println("afterThrowing.....");
    }

    //环绕通知，在方法之前之后都会执行
    @Around(value = "pointDemo()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("环绕之前......");

        //被增强的方法执行
        proceedingJoinPoint.proceed();

        System.out.println("环绕之后......");
    }
}
